node 大写_大写Node.js模块

本文介绍了如何使用Node.js的第三方模块`upper-case`来实现字符串的大写转换。即使在源代码中输入小写字母,这个模块也能帮助我们在输出时显示大写字母。文章通过创建一个HTTP服务器展示`upper-case`模块的基本用法,该服务器将输出'HELLO WORLD',尽管在源代码中是小写的。
摘要由CSDN通过智能技术生成

node 大写

Today, let's see a third party module that helps us in working with upper-case letters without necessarily typing them in upper-case in our source code.

今天,让我们看一个第三方模块,它可以帮助我们处理大写字母,而不必在源代码中以大写字母键入它们。

You may find it useless! But it's very important.

您可能会发现它没有用! 但这很重要。

For example, you may have a form where you require your users to fill in upper-case letters only. You may wish to add a function where any typed in the letter appears in upper-case even though typed in lower-case from the keyboard.

例如,您可能有一个表单,要求您的用户仅填写大写字母。 您可能希望添加一个功能,即使从键盘输入小写字母,字母中的任何字母都以大写形式显示。

Like said before, Node modules are like libraries which help us perform specific tasks. Node.JS is always considered powerful because it has a very large ecosystem of third-party modules.

如前所述,Node模块就像是可以帮助我们执行特定任务的库。 Node.JS一直被认为是功能强大的,因为它具有非常庞大的第三方模块生态系统。

The upper-case module is a third-party module built by some experts to help us.

大写模块是一些专家构建的第三方模块,可以帮助我们。

Take Note! You should have Node.js installed in your PC.

做记录! 您应该在PC中安装了Node.js。

With Node.js already up and running, let's get started.

在Node.js已经启动并运行的情况下,让我们开始吧。

Now, let's get started.

现在,让我们开始吧。

First of all, install the upper-case module by typing npm install upper-case via the command line.

首先,通过在命令行中键入npm install upper-case来安装大写 模块

upper-case module in Node.js

Wait for a while as it downloads.
NB: Internet required!

等待下载。
注意:需要互联网!

Take note that only third party modules are installed via command line unlike built in modules which comes along with the node.js environment when downloaded...

请注意,不同于第三方模块在下载时随Node.js环境一起提供的内置模块,仅通过命令行安装了第三方模块。

Let's look at a basic use of the upper-case module.

让我们看一下大写模块的基本用法。

We'll create an http server that will output hello world in capital letters but written in small letters in the source code.

我们将创建一个http服务器,该服务器将以大写字母输出问候世界,但在源代码中以小写字母书写。

Open a text editor and type the following code and save it with the file name app.js:

打开一个文本编辑器,输入以下代码,并将其保存为文件名app.js

var http = require('http');  // includes the http module
var uc = require('upper-case'); // include the upper-case module
http.createServer(function (req, res) {
    res.writeHead(200, {'Content-Type': 'text/html'});
    res.write(uc("hello world!")); // assign the upper-case module
    res.end();
}).listen(8080); // port number

Note: The file should be saved in your default Node.js directory.

注意:该文件应保存在默认的Node.js目录中。

Initiate the JavaScript file at the console by typing node app.js

通过键入节点app.js在控制台上启动JavaScript文件

Take Note! : Your command line directory should be same with Node.js module directory.

做记录! :您的命令行目录应与Node.js模块目录相同。

Finally, open your browser and navigate to http://localhost:8080

最后,打开浏览器并导航到http:// localhost:8080

upper-case module in Node.js

Thanks for coding with me. Your comments are most welcome.

感谢您与我一起编码。 非常欢迎您发表评论。

翻译自: https://www.includehelp.com/node-js/upper-case-node-js-module.aspx

node 大写

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值